<?php

//就近 www.jiujin.me
if (!defined('IN_IA')) {
	die('Access Denied');
}
function sortByCreateTime($a, $b)
{
	if ($a['createtime'] == $b['createtime']) {
		return 0;
	} else {
		return $a['createtime'] < $b['createtime'] ? 1 : -1;
	}
}
class CommissionMobile extends Plugin
{
	protected $set = null;
	public function __construct()
	{
		parent::__construct('commission');
		$this->set = $this->getSet();
		global $_W,$_GPC;
		$agentid = $_GPC['agentid'];
		$openid = m('user')->getOpenid();
		$member = m('member')->getMember($openid);
		//这里判断是否是分享页面
		if($_GPC['method'] != 'register' && $_GPC['method'] != 'myshop') {
			if($_GPC['mid'] && $_GPC['mid'] != $member['id']){
				/*gmm 2015-11-25 不是这思路
				//发展会员,进入商品详情页
				//gmm 补充 2015-11-25 招募令进来的有其对应的agentlevel
				$uplevel = pdo_fetch("SELECT agentlevel FROM " . tablename('ewei_shop_member') . " WHERE uniacid = :uniacid AND id = :id ", array(':uniacid' => $_W['uniacid'],':id' => $_GPC['mid']));
				$uplevel = $uplevel['agentlevel'];
				if($uplevel && $uplevel == 1){		//是战略合作伙伴邀请我
					pdo_update('ewei_shop_member', array('agentlevel' => 2), array('uniacid' => $_W['uniacid'], 'id' => $member['id']));
				}elseif($uplevel && $uplevel == 2){		//是大伙伴邀请我
					pdo_update('ewei_shop_member', array('agentlevel' => 3), array('uniacid' => $_W['uniacid'], 'id' => $member['id']));
				}else{
					
				}
				if($_GPC['method'] == 'ruanwen'){
					header('location:' . $this->createMobileUrl('shop'));
					die;
				}else{
					header("location: " . $this->createMobileUrl('shop/detail',array('id'=>$_GPC['goodsid'])));
					die;
				}*/
                                    unset($_GPC['mid']);
			}else{
				if ($member['isagent'] != 1 || $member['status'] != 1) {
					if($_GPC['method'] == 'ruanwen'){	
						//进入首页
						header('location:' . $this->createMobileUrl('shop'));
						die;
					}else if($_GPC['method'] == 'fenxiang'){
					
					}else{
						//进入招募页面
						header('location:' . $this->createPluginMobileUrl('commission/register',array('agentid'=>$agentid)));
						die;
					}
					
				}
			}
		}
	}
	public function index()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
        public function editor_article()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
	public function team()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
	public function order()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
	public function withdraw()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
	public function apply()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
	public function shares()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
	public function register()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
	public function myshop()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
	public function log()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
	public function zhaomu()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
	public function confirm()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
	public function fenxiang()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
	public function ruanwen()
	{
		$this->_exec_plugin(__FUNCTION__, false);
	}
}